<?php
/**
 * redis sub(消息订阅端)
 * @ blog: phping.sinaapp.com
 * @date 2016-04-24 15:00
 */

$redis = new Redis(); 
$res = $redis->pconnect('127.0.0.1', 6379,0);
$redis->auth('secret@huoyan.com');
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
$redis->subscribe(array('successWithdrawals','realPayconfirm','bindbanklist','testloanMoney','bindoldcard'), 'callback');

// 回调函数,这里写处理逻辑
function callback($instance, $channelName, $message) { 
	switch ($channelName)
	{
		case 'bindbanklist'://实际绑卡操作 
			echo '---审批通|过|绑卡'.$channelName.'频道新消息---|'.$message.'|';
			post_('http://rongapi.huoyanzichan.com/Home/Pay/lpopListBindBank');
			break; 
		case 'testloanMoney'://测试放款
			post_('http://rongapi.huoyanzichan.com/Home/WithdrawalsOrder/testloanMoney');	
			break; 
		case 'successWithdrawals'://审批通过后实际放款
			echo '---审批通过'.$channelName.'频道新消息'.$message.'---|';
			post_('http://rongapi.huoyanzichan.com/Home/WithdrawalsOrder/loanMoney');	
			break; 
		case 'bindoldcard': //选择银行卡成功后|新卡旧卡|开始实际放款
			echo '---银行卡选择成功'.$channelName.'频道新消息---|'.$message.'';
			post_('http://rongapi.huoyanzichan.com/Home/WithdrawalsOrder/loanMoney');	
			break; 
		case 'realPayconfirm'://实际还款
			echo '---审批通过'.$channelName.'频道新消息---|'.$message.'|';
			post_('http://rongapi.huoyanzichan.com/Home/Pay/rongPayconfirm');	
			break; 
		default:
	 
	}
  
}
  
function post_($url){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HEADER, 1);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	// 设置	头信息（当用IP直接访问时，加这个如：https://baibu.com -> 220.15.23.5）
	// curl_setopt($ci, CURLOPT_HTTPHEADER, array('Host:baibu.com'));

	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //这个是重点,规避ssl的证书检查。
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 跳过host验证
	$data = curl_exec($curl);
	echo '请求的url'.$url.'|结果：'.json_encode($data).'|';
	curl_close($curl);
}

